import 'package:my_blog_flutter/generated/json/base/json_convert_content.dart';
import 'package:my_blog_flutter/app/modules/login/models/login_entity.dart';

LoginEntity $LoginEntityFromJson(Map<String, dynamic> json) {
  final LoginEntity loginEntity = LoginEntity();
  final int? code = jsonConvert.convert<int>(json['code']);
  if (code != null) {
    loginEntity.code = code;
  }
  final String? message = jsonConvert.convert<String>(json['message']);
  if (message != null) {
    loginEntity.message = message;
  }
  final LoginData? data = jsonConvert.convert<LoginData>(json['data']);
  if (data != null) {
    loginEntity.data = data;
  }
  final int? timestamp = jsonConvert.convert<int>(json['timestamp']);
  if (timestamp != null) {
    loginEntity.timestamp = timestamp;
  }
  return loginEntity;
}

Map<String, dynamic> $LoginEntityToJson(LoginEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['code'] = entity.code;
  data['message'] = entity.message;
  data['data'] = entity.data?.toJson();
  data['timestamp'] = entity.timestamp;
  return data;
}

extension LoginEntityExtension on LoginEntity {
  LoginEntity copyWith({
    int? code,
    String? message,
    LoginData? data,
    int? timestamp,
  }) {
    return LoginEntity()
      ..code = code ?? this.code
      ..message = message ?? this.message
      ..data = data ?? this.data
      ..timestamp = timestamp ?? this.timestamp;
  }
}

LoginData $LoginDataFromJson(Map<String, dynamic> json) {
  final LoginData loginData = LoginData();
  final String? token = jsonConvert.convert<String>(json['token']);
  if (token != null) {
    loginData.token = token;
  }
  final String? username = jsonConvert.convert<String>(json['username']);
  if (username != null) {
    loginData.username = username;
  }
  return loginData;
}

Map<String, dynamic> $LoginDataToJson(LoginData entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['token'] = entity.token;
  data['username'] = entity.username;
  return data;
}

extension LoginDataExtension on LoginData {
  LoginData copyWith({
    String? token,
    String? username,
  }) {
    return LoginData()
      ..token = token ?? this.token
      ..username = username ?? this.username;
  }
}